package com.my.apacheDBUtils;

import com.my.user.util.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

public class UpdateDemo {
    public static void add() throws SQLException {
        QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSourceWithC3P0ByXML());
        String sql = "insert into student(id,name,age) values(?,?,?)";
        int count = runner.update(sql,new Object[]{4,"ls",20});
        System.out.println(count);
    }

    public static void update() throws SQLException {
        QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSourceWithC3P0ByXML());
        String sql = "update student set name=?,age=? where id=?";
        int count = runner.update(sql,new Object[]{"xl",22,4});
        System.out.println(count);
    }

    public static void delete() throws SQLException {
        QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSourceWithC3P0ByXML());
        String sql = "delete from student where id=?";
        int count = runner.update(sql,4);
        System.out.println(count);
    }

    public static void main(String[] args) throws SQLException {
        delete();
    }
}
